<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备消息绑定列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>设备类型：</label>
                            <select name="deviceType" th:with="type=${@dict.getType('gy_device_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>用户名：</label>
                            <input type="text" name="user.userName"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="search" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="gy:mgt:add">
                <i class="fa fa-plus"></i> 新增
            </a>

<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
<!--               shiro:hasPermission="gy:mgt:remove">-->
<!--                <i class="fa fa-remove"></i> 删除-->
<!--            </a>-->
<!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gy:mgt:export">-->
<!--                <i class="fa fa-download"></i> 导出-->
<!--            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('gy:mgt:edit')}]];
    var removeFlag = [[${@permission.hasPermi('gy:mgt:remove')}]];
    var deviceTypeDatas = [[${@dict.getType('gy_device_type')}]];
    var isPrincipalDatas = [[${@dict.getType('gy_device_principal')}]];
    var prefix = ctx + "gy/mgt";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "设备消息绑定",
            columns: [
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'deviceType',
                    title: '设备类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(deviceTypeDatas, value);
                    }
                },
                {
                    field: 'user.userName',
                    title: '用户名'
                },
                {
                    field: 'user.phonenumber',
                    title: '手机'
                },

                {
                    field: 'isPrincipal',
                    title: '人员类型',
                    formatter: function (value, row, index) {
                        console.log(value)
                        if (value == 1) {
                            return '责任人';
                        } else if (value == null || value == "") {
                            return '相关人';
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        console.log(row)
                        if (row.isPrincipal == null || row.isPrincipal == "") {
                            actions.push('<a class="btn btn-warning  btn-xs  ' + editFlag + '" href="javascript:void(0)" onclick="setPrinicipal(\'' + row.id + '\')">设置为责任人</a> ');
                        } else {
                            actions.push('<a class="btn btn-warning  btn-xs  ' + editFlag + '" href="javascript:void(0)" onclick="setRelate(\'' + row.id + '\')">设置为相关人</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')">编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')">删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function setPrinicipal(id) {

        $.modal.confirm("确定设置该条信息为责任人吗？", function () {
            $.operate.saveModal(prefix + "/setPrinicipal", {"id": id}, function () {
                $("#search").click();
            });
        });

    }

    function setRelate(id) {

        $.modal.confirm("确定设置该条信息为相关人吗？", function () {
            $.operate.saveModal(prefix + "/setRelate", {"id": id}, function () {
                $("#search").click();
            });
        });

    }

</script>
</body>
</html>
